home *** CD-ROM | disk | FTP | other *** search
/ More MacCube 1: Arcade Games / More MacCube Vol 1 Arcade Games.bin / Games⁄Arcade / Bolo / More information / Sample Code / Std Autopilot / BF_Interface.c < prev    next >
Encoding:
Text File  |  1995-04-28  |  2.1 KB  |  88 lines  |  [TEXT/KAHL]

  1. // Bolo code (C) Stuart Cheshire <cheshire@cs.stanford.edu> 1987-1995.
  2. // All rights reserved. This code is owned by Stuart Cheshire and is donated
  3. // free of charge for non-commercial use. You may not use this code in any
  4. // product sold for commercial profit, except shareware priced at $25 or less.
  5.  
  6. #include "BrainFrame.h"
  7. #include "BF_ResourceIDs.h"
  8. #include "BF_Events.h"
  9. #include "BF_Main.h"
  10. #include "BF_Utils.h"
  11. #include "BF_Globals.h"
  12. #include "BF_Interface.h"
  13. #include "BF_IAC.h"
  14.  
  15. local OSErr UpdateInfo(ConnectionInfo *conn)
  16.     {
  17.     OSErr retcode;
  18.     static long last_call = 0;
  19.     if (last_call == TickCount()) return(noErr);
  20.     else last_call = TickCount();
  21.  
  22.     retcode = CallBolo(conn, BoloView);
  23.     if (retcode) return(retcode);
  24.     
  25.     return(retcode);
  26.     }
  27.  
  28. export void BFInterfaceUpdateWindow(ConnectionInfo *conn)
  29.     {
  30.     SetPort(conn->win);
  31.     MoveTo(20,40);
  32.     DrawString("\pBrainFrame connected to Bolo player “");
  33.     DrawString(conn->portinfo.name);
  34.     DrawString("\p”");
  35.     }
  36.  
  37. local void CallBrain(ConnectionInfo *conn, u_short operation, u_short menu_item)
  38.     {
  39.     extern BoloBrain BrainMain;
  40.     if (UpdateInfo(conn)) return;
  41.     conn->info->operation = operation;
  42.     conn->info->menu_item = menu_item;
  43.     BrainMain(conn->info);
  44.     }
  45.  
  46. export void BFInterfaceIdle(ConnectionInfo *conn)
  47.     {
  48.     if (UpdateInfo(conn)) return;
  49.     CallBrain(conn, BRAIN_THINK, 0);
  50.     }
  51.  
  52. export void BFInterfaceMenu(ConnectionInfo *conn, u_short menu, u_short item)
  53.     {
  54.     if (UpdateInfo(conn)) return;
  55.     CallBrain(conn, menu, item);
  56.     }
  57.  
  58. export OSErr BFInterfaceOpen(ConnectionInfo *conn)
  59.     {
  60.     OSErr retcode = noErr;
  61.     static const Rect r = { 40, 10, 120, 410 };
  62.  
  63.     conn->win = NewWindow(NULL,&r,"\pBrain",TRUE,zoomDocProc,(WindowPtr)-1,TRUE,0);
  64.     
  65.     // Comment out the following line if making a passive viewer that doesn't
  66.     // override the tank controls, and Bolo will continue to operate the tank
  67.     // under manual control.
  68.     retcode = CallBolo(conn, BoloControl);
  69.     
  70.     CallBrain(conn, BRAIN_OPEN, 0);
  71.     return(retcode);
  72.     }
  73.  
  74. export void BFInterfaceClose(ConnectionInfo *conn)
  75.     {
  76.     if (conn->win) DisposeWindow((GrafPtr)conn->win);
  77.     CallBrain(conn, BRAIN_CLOSE, 0);
  78.     }
  79.  
  80. export OSErr BFInterfaceInit(void)
  81.     {
  82.     return(noErr);
  83.     }
  84.  
  85. export void BFInterfaceQuit(void)
  86.     {
  87.     }
  88.